package net.oschina.app.fragment.me;

import android.app.AlertDialog;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.google.zxing.encoding.EncodingHandler;

import net.oschina.app.R;
import net.oschina.app.base.BaseFragment;
import net.oschina.app.base.Global;
import net.oschina.app.ui.activity.me.FansActivity;
import net.oschina.app.ui.activity.me.MessageCenterActivity;
import net.oschina.app.ui.activity.me.MyInfoActivity;
import net.oschina.app.ui.activity.me.NoticeActivity;
import net.oschina.app.ui.activity.me.UserBlogActivity;
import net.oschina.app.ui.activity.me.UserCollectActivity;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import de.hdodenhof.circleimageview.CircleImageView;

/**
 * Created by Shinelon on 2017/1/13.
 */

public class MeFragment extends BaseFragment {
    @BindView(R.id.iv_find)
    ImageView mIvFind;
    @BindView(R.id.ll_cores)
    LinearLayout mLlCores;
    @BindView(R.id.ll_collection)
    LinearLayout mLlCollection;
    @BindView(R.id.ll_notice)
    LinearLayout mLlNotice;
    @BindView(R.id.ll_fans)
    LinearLayout mLlFans;
    @BindView(R.id.ll_news)
    LinearLayout mLlNews;
    @BindView(R.id.ll_blogs)
    LinearLayout mLlBlogs;
    @BindView(R.id.ll_note)
    LinearLayout mLlNote;
    @BindView(R.id.ll_team)
    LinearLayout mLlTeam;
    @BindView(R.id.iv_news)
    ImageView mIvNews;
    @BindView(R.id.iv_info1)
    CircleImageView mIvInfo;

    @Override
    public int getLayoutRes() {
        return R.layout.fragment_me;

    }

    @Override
    public void initView() {

    }

    @Override
    public void initListener() {

    }

    @Override
    public void initData() {

    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // TODO: inflate a fragment view
        View rootView = super.onCreateView(inflater, container, savedInstanceState);
        ButterKnife.bind(this, rootView);
        return rootView;
    }

    @OnClick({R.id.iv_find, R.id.ll_cores, R.id.ll_collection, R.id.ll_notice, R.id.ll_fans,
            R.id.ll_news, R.id.ll_blogs, R.id.ll_note, R.id.ll_team,R.id.iv_info1})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.iv_find:
                openQRCodeDialog();
                break;
            case R.id.ll_cores:
                break;
            case R.id.ll_collection:
                Intent intent = new Intent(getActivity(), UserCollectActivity.class);
                startActivity(intent);
                break;
            case R.id.ll_notice:
                Intent intent1 = new Intent(getActivity(), NoticeActivity.class);
                startActivity(intent1);
                break;
            case R.id.ll_fans:
                Intent intent2 = new Intent(getActivity(), FansActivity.class);
                startActivity(intent2);
                break;
            case R.id.iv_info1:
                Intent intent3 = new Intent(getActivity(), MyInfoActivity.class);
                startActivity(intent3);
                break;
            case R.id.ll_news:
                Intent intent4 = new Intent(getActivity(), MessageCenterActivity.class);
                startActivity(intent4);
                break;
            case R.id.ll_blogs:
                Intent intent5 = new Intent(getActivity(), UserBlogActivity.class);
                startActivity(intent5);
                break;
            case R.id.ll_note:
                break;
            case R.id.ll_team:
                break;
        }
    }
    private void openQRCodeDialog() {
        Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.clap);
        Bitmap map = EncodingHandler.createQRCode("http://www.baidu.com/", Global.dp2px(400), Global.dp2px(400), bitmap);

        AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
//        AlertDialog customDialog;
        LayoutInflater inflater = getActivity().getLayoutInflater();
        View layout = inflater.inflate(R.layout.qrcode, null);

        ImageView ivqrCode = (ImageView) layout.findViewById(R.id.iv_qrcode);
        ivqrCode.setImageBitmap(map);
        builder.setView(layout);
        builder.show();
    }

}
